import { _decorator, AudioClip, Component, Node } from 'cc';
import { SSS_Consts } from "../../../../Script/Data/SSS_Consts";
import { bdlMgr } from "../../../../Script/Manager/BundleManager_S";
import SSS_GameEventManager, { SS_GameEventData } from "../../../../Script/Manager/SSS_GameEventManager";
import { SSS_AudioManager } from 'db://assets/Script/Manager/SSS_AudioManager';
import DaoShuiPaiXu_GameManager from '../DaoShuiPaiXu_GameManager';

const { ccclass, property } = _decorator;

@ccclass('DaoShuiPaiXu_WinPanel')
export default class DaoShuiPaiXu_WinPanel extends Component {
    public static Instance: DaoShuiPaiXu_WinPanel;

    @property(Node)
    public Button_menu: Node | null = null;
    @property(Node)
    public Button_next: Node | null = null;

    onLoad() {
        DaoShuiPaiXu_WinPanel.Instance = this;
    }
    ShowOn() {
        this.node.active = true;
        this.AddListener();
        this.Refresh();

        let r = 4;
        let audio_root = `audio/Win sound/Win sound ${r}`;
        console.log(`audio_root`, audio_root);

        bdlMgr.getRes<AudioClip>(SSS_Consts.BundleName.AUDIO, audio_root, AudioClip).then(res => {
            SSS_AudioManager.Instance.playSFX(res, false);
        });
    }
    ShowOff() {
        this.node.active = false;
        this.RemoveListener();
    }
    async Refresh() {

    }
    AddListener() {
        this.Button_menu.on(Node.EventType.TOUCH_END, this.On_Button_menu, this);
        this.Button_next.on(Node.EventType.TOUCH_END, this.On_Button_next, this);
    }
    RemoveListener() {
        this.Button_menu.off(Node.EventType.TOUCH_END, this.On_Button_menu, this);
        this.Button_next.off(Node.EventType.TOUCH_END, this.On_Button_next, this);
    }
    On_Button_menu() {
        this.ShowOff();
        SSS_GameEventManager.eventTarget.emit(SS_GameEventData.Menu);
        SSS_AudioManager.PlayButtonAudio();
    }

    On_Button_next() {
        // console.log(`On_Button_next`);
        this.ShowOff();
        DaoShuiPaiXu_GameManager.Instance.下一关();
    }
}